package com.vpx;

import com.googlecode.javacv.cpp.opencv_core;
import static com.vpx.CodecBase.getImageAddress;

/**
 * @author sad
 */
public class VpxDecoder extends CodecBase {

    private long codecPointer;
    private final int width;
    private final int height;

    public VpxDecoder(int width, int height) {
        this.width = width;
        this.height = height;
        JniVpx.createDecoder(this);
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public boolean decodeImage(final opencv_core.IplImage image, byte[] encodedFrame) {
        long address = getImageAddress(image);
        return JniVpx.decodeFrame(this, encodedFrame, address);
    }

    @Override
    protected void finalize() throws Throwable {
        JniVpx.destroyDecoder(this);
        super.finalize();
    }

}
